<!DOCTYPE html>
<html>
  <head>
      <script src="https://cdn.jsdelivr.net/npm/vue/dist/vue.js"></script>
  </head>
  <body>
    <div id="app">
      <localassembly></localassembly>
      <global-assembly></global-assembly>

    </div>
    <script>
    
    // 局部组件
    const tmp = new Vue()
    
    Vue.component('global-assembly',{
      template: '<input type="button" value="点击此按钮" @click="clickme" />',
      methods: {
        clickme(){
          tmp.$emit('addcart',1)
        }
      }
    })

    const localassembly =  {
      template: '<div><span>这是第 {{ num }} 件商品</span> </div>',
      data() {
        return {
          num: 0
        }
      },
      created() {
        tmp.$on('addcart',(val) => {
          this.num += val
        })
      }
    }


    const vm = new Vue({
      el: '#app',
      components: {
        localassembly
      }
    })
    </script>
  </body>
</html>